import Koa from 'koa';
import Router from 'koa-router';
import { DB } from './db/index.js';
import { getcontrollerUrl, regController } from './util/tool.js';
import { appPort } from './config/appStting.js'; // 确保路径正确
import bodyparser from 'koa-bodyparser';


const app = new Koa();
app.use(bodyparser())

const router = new Router();

// 注册路由
const controllerFiles = getcontrollerUrl(); // 确保工具函数返回正确路径
regController(router, controllerFiles);

app.use(router.routes());
app.use(router.allowedMethods());

// 初始化数据库
DB();

// 启动服务器
app.listen(appPort, () => {
  console.log(`🚀 Server running on http://localhost:${appPort}`);
});